import 'package:flutter/material.dart';
import 'package:getx_scaffold/common/widgets/icon_x.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/utils/url_utils.dart';
import 'package:oramemo/entity/device_mine_entity.dart';
import 'package:oramemo/generated/assets.dart';
import 'package:oramemo/pages/transcription/transcription_router.dart';
import 'package:oramemo/widget/gradient_filled_button.dart';
import 'package:oramemo/common/langs/text_key.dart';

class DeviceWidget extends StatelessWidget {
  final DeviceMineData data;

  const DeviceWidget({
    super.key,
    required this.data,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.fromLTRB(16, 60, 16, 16),
      decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(16))),
      child: Padding(
        padding: const EdgeInsets.fromLTRB(16,12, 16, 16),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(8),
              child: const IconX.image(
                Assets.facilityHardware,
                width: 80,
                height: 80,
                fit: BoxFit.cover,
              ),
            ),
            const SizedBox(width: 16),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Expanded(
                        child: Text(data.deviceName ?? '',
                            style: const TextStyle(
                                fontSize: 20, fontWeight: FontWeight.bold)),
                      ),
                      const SizedBox(width: 8),
                      InkWell(
                          onTap: () {
                            Get.toNamed(TranscriptionRouter.transcriptionRecoder);
                          },
                          child: const IconX.image(
                            Assets.transcriptionRecord,
                            size: 28,
                          ))
                    ],
                  ),
                  const SizedBox(height: 8),
                  Row(
                    children: [
                      const IconX.image(Assets.facilityLocation, size: 18),
                      Expanded(
                        child: Text(
                          data.device?.deviceAddress ?? '',
                          style:
                              const TextStyle(fontSize: 12, color: Colors.grey),
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 5),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Padding(
                        padding: const EdgeInsets.only(bottom: 8.0),
                        child: Row(
                          children: [
                            const IconX.image(Assets.facilityListening, size: 18),
                            Text('${data.device?.deviceGear ?? ''}${TextKey.gear.tr}',
                                style: const TextStyle(
                                    fontSize: 12, color: Colors.grey)),
                          ],
                        ),
                      ),
                      GradientFilledButton(
                          onPressed: () {
                            UrlUtil.launchTelURL(data.device?.deviceTelnum ?? '');
                          },
                          text: TextKey.deviceCallButton.tr),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
